/**
 * 
 */
package com.wskj.library.service.impl;

import java.util.List;

import com.wskj.library.dao.UserInfoDao;
import com.wskj.library.dao.impl.UserInfoDaoImpl;
import com.wskj.library.pojo.UserInfo;
import com.wskj.library.service.UserService;

/**
 * @author 胡洋
 * @describe  管理用户的服务的类
 * @Date 2018年3月22日下午5:51:37
 * @version 1.0
 */
public class UserServiceImpl implements UserService {
     
	UserInfoDao  userDao=new UserInfoDaoImpl();
	
	
	
	@Override
	public UserInfo checkLogin(String name, String pass) {
		
		return userDao.checkLogin(name,pass);
	}



	
	@Override
	public UserInfo getUserById(int uid) {		
		return userDao.getUserInfoById(uid);
	}




	
	@Override
	public long getCountsByName(String name, String deposite, String address,String sex) {
		
		return userDao.getCountsByName(name,deposite,address,sex);
	}




	
	@Override
	public List<UserInfo> getUserWithPage(String name, String deposite, String address, String sex, int index,
			int pageSize) {
		
		return userDao.getUserWithPage(name,deposite,address,sex,index,pageSize);
	}




	
	@Override
	public boolean deleteUserById(int id) {
		
		//判断读者押金是否 为0  ，不为0 不能删除读者信息  
		UserInfo user = userDao.getUserInfoById(id);
		
		double deposite = user.getDeposite();
		
		if(deposite>0) {
			return false;
		}		
		int count = userDao.deleteById(id);
		return count>0?true:false;
	}




	
	@Override
	public boolean updateUserInfo(UserInfo user) {
		int count = userDao.updateUserInfo(user);
		return count>0?true:false;
	}




	
	@Override
	public boolean saveUser(UserInfo user) {
	 int count = userDao.addUserInfo(user);
		return count>0?true:false;
	}
	
	

}
